package com.eupmt.lab3.controllers.impl;

import com.eupmt.lab3.controllers.IRolController;
import com.eupmt.lab3.domain.Rol;
import com.eupmt.lab3.persistence.ibatis.dao.RolDaoManager;
import com.eupmt.lab3.utils.Log;
import java.util.List;

/**
 *
 * @author sony
 */
public class RolController implements IRolController {

    //Atributes
    protected static RolController instance = null;
    private RolDaoManager dao = null;
    private Log log = null;

    //Constructors
    private RolController() {
        log = new Log();
    }

    //Methods
    public void saveRol(Rol rol) throws Exception {
        dao = RolDaoManager.getInstance();
        dao.saveRol(rol);
    }

    public void insertRol(Rol rol) throws Exception {
        dao = RolDaoManager.getInstance();
        dao.insertRol(rol);
    }

    public void updateRol(Rol rol) throws Exception {
        dao = RolDaoManager.getInstance();
        dao.updateRol(rol);
    }

    public void deleteRol(Rol rol) throws Exception {
        dao = RolDaoManager.getInstance();
        dao.deleteRol(rol);
    }


    public Rol getRolById(int idRol) throws Exception {
        dao = RolDaoManager.getInstance();
        return dao.getRolById(idRol);
    }

    public Rol getRolByNom(String nom) throws Exception {
        dao = RolDaoManager.getInstance();
        return dao.getRolByNom(nom);
    }

    public List<Rol> getAllRols() throws Exception {
        dao = RolDaoManager.getInstance();
        return dao.getAllRols();
    }

    public List<Rol> getRolsLikeNom(String nom) throws Exception {
        dao = RolDaoManager.getInstance();
        return dao.getRolsLikeNom(nom);
    }

    // Patró Singleton
    public static RolController getInstance() {
        if (instance == null) {
            instance = new RolController();
        }

        return instance;
    }
}